package org.brisling.oa.queryService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.common.util.StringUtil;
import org.brisling.oa.domain.OABizinfo;
import org.brisling.oa.queryService.base.AbstractOAQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * <p>Title: QueryOABizinfoService</p>
 * <p>Description: oa业务通用查询服务类</p>
 * <p>Company: tongking</p>
 * @author jackson wang
 * @since 1.0
 * @version 1.0
 * @date 2016年7月9日 上午12:31:45
 */
@RestController
//映射路径
@RequestMapping("/oaBizinfo/query")
                                                                  //实体泛型类型
public class QueryOABizinfoService extends AbstractOAQueryService<OABizinfo> {
	
	
	public QueryOABizinfoService(){
		this.moduleName = ConstSysParam.MODULE_OA_BIZINFO;
		this.subSystem = ConstSysParam.SUBSYSTEM_OA;
		this.tableName = ConstSysParam.VIEW_PREFIX +this.moduleName;
		this.clazz = OABizinfo.class;
		
		typeMap = this.getTypeMap(clazz);
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
		
	
	@RequestMapping("/getListDomain.action")
	public ListDomain<OABizinfo> getListDomain(
			@RequestBody(required=false) String body){		
		
		return super.getListDomainByConditionAndOrder(body, typeMap, orderMap,true);
	}
	
	@RequestMapping("/getOperateTaskListDomain.action")
	public ListDomain<OABizinfo> getUserCanoperateTask(@RequestBody(required=false) String body){
		return super.getUserCanoperateTask(body);
	}
	
	@RequestMapping("/getSignedTaskListDomain.action")
	public ListDomain<OABizinfo> getUserSignedTask(@RequestBody(required=false) String body){
		return super.getUserSignedTask(body);
	}
	
	@RequestMapping("/getUnsignedTaskListDomain.action")
	public ListDomain<OABizinfo> getUserUnsignedTask(@RequestBody(required=false) String body){
		return super.getUserUnsignedTask(body);
	}
	
	
	@RequestMapping("/getFinishedTaskListDomain.action")
	public ListDomain<OABizinfo> getUserFinishedTask(@RequestBody(required=false) String body){
		return super.getUserFinishedTask(body);
	}
	
	@RequestMapping("/getUserManagedTaskDomain.action")
	public ListDomain<OABizinfo> getUserManagedTask(@RequestBody(required=false) String body){
		return super.getUserManagedTask(body);
	}
	
	@RequestMapping("/getAllTaskListDomain.action")
	public ListDomain<OABizinfo> getAllTask(@RequestBody(required=false) String body){
		return super.getAllTask(body);
	}
	
	@RequestMapping("/getTaskListDomain.action")
	public ListDomain<OABizinfo> getTaskListDomain(@RequestBody(required=false) String body){
		return super.getTaskListDomain(body);
	}
	
	
	/**
	 * 根据业务id查找业务记录
	 * @param id	业务id
	 * @return  	业务记录 
	 */
	@RequestMapping("/getOne.action")
	public OABizinfo getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}
	
	/**
	 * 根据唯一编码查找业务记录
	 * @param identify	业务唯一编码
	 * @return 业务记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public OABizinfo getOneByIdentify(@RequestParam(value="identify",required=false) String identify){	
		return super.getOneByIdentify(identify);
	}
	
	/**
	 * 根据唯一编码查找业务信息
	 * @param field		字段名称
	 * @param fieldVal	字段值
	 */
	@RequestMapping("/getOneByField.action")
	public OABizinfo getOneByField(@RequestParam(value="field",required=false) String field,
			@RequestParam(value="fieldVal",required=false) String fieldVal){	
		return super.getOneByIdentify(field,fieldVal);
	}
	
	/**
	 * 根据唯一编码查找业务信息
	 * @param field		字段名称
	 * @param fieldVal	字段值
	 */
	@RequestMapping("/getOneByFlowInstId.action")
	public OABizinfo getOneByFlowInstId(
			@RequestParam(value="flowInstId",required=false) String flowInstId){
		
		if(flowInstId!=null){
			String sql = dicService.getSqlByBizcode("oaGenerel_query_one");
			if(sql!=null){
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("flowinstid", flowInstId);
				sql = StringUtil.formatSql(sql, map);				
				return super.getOneBySql(sql);
			}
		}
		return null;
	}
	
	
	/**
	 * 根据唯一编码查找业务信息
	 * @param field		字段名称
	 * @param fieldVal	字段值
	 */
	@RequestMapping("/getPurchaseOneByFlowInstId.action")
	public OABizinfo getPurchaseOneByFlowInstId(
			@RequestParam(value="flowInstId",required=false) String flowInstId){
		
		if(flowInstId!=null){
			String sql = dicService.getSqlByBizcode("oaPurchase_query_one");
			if(sql!=null){
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("flowinstid", flowInstId);
				sql = StringUtil.formatSql(sql, map);				
				return super.getOneBySql(sql);
			}
		}
		return null;
	}
	
	
	
	/**
	 * 返回流程记录流程实例的执行记录
	 * @param body	包含procInstId在内的参数信息
	 * @return
	 */
	
	@RequestMapping("/flowHistoricsListDomain.action")
	public ListDomain<Object> getHistoricByProcInstId(@RequestBody(required=false) String body){
		
		String sql = dicService.getSqlByBizcode("flow_historics");				
		return super.getHistoricByProcInstId(body, sql);
	}
	
	public String generateBizno(){
		return super.generateBizno();
	}
	

	public List<OABizinfo> getAllList(String sql){
		return super.getAllList(sql);
	}
	
	
}
